<?php /* Smarty version 2.6.22, created on 2012-02-20 15:42:06
         compiled from Admin/Deals/index.tpl */ ?>
<?php require_once(SMARTY_CORE_DIR . 'core.load_plugins.php');
smarty_core_load_plugins(array('plugins' => array(array('modifier', 'number_format', 'Admin/Deals/index.tpl', 65, false),)), $this); ?>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/i18n/jquery-ui-i18n.min.js"></script>
<style type="text/css">
.main_column {
	margin-right: 20px;
}
</style>
<div class="box">
	<div class="header">
		Quản lý Deals
	</div>
	<div class="body">
		<div class="panes">
			<div>
	
				<a href="<?php echo $this->_tpl_vars['APPLICATION_URL']; ?>
/Admin/Groupon/add">Tạo mới deal</a>
				<form action="" method="post">
				<table border="0" cellpadding="0" cellspacing="0" class="grid_table wf">
					<thead>
						<tr>
							<th width="10">ID</th>
							<th width="120">Tên Groupon</th>
							<th width="120">Ngày bắt đầu</th>
							<th width="120">Ngày kết thúc</th>
                            <th width="120">Giá bán</th>
							<th>Giá gốc</th>
							<th>Thể loại</th>
							<th>Tình trạng</th>
							<th align="center">Action</th>
						</tr>
						<tr>
							<th></th>
							<th><input type="text" name="groupon_name" value="<?php echo $this->_tpl_vars['groupon_name']; ?>
"></th>
							<th><input type="text" name="started_deal" class="started_deal" value="<?php echo $this->_tpl_vars['started_deal']; ?>
"></th>
							<th><input type="text" name="expired_deal" class="expired_deal" value="<?php echo $this->_tpl_vars['expired_deal']; ?>
"></th>
                            <th></th>
							<th></th>
							<th>
								<select name="category">
								<option value="">Tất cả</option>
									<?php $_from = $this->_tpl_vars['categoryList']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars['item']):
?>
										<option value="<?php echo $this->_tpl_vars['item']->id; ?>
" <?php if ($this->_tpl_vars['item']->id == $this->_tpl_vars['category']): ?>selected<?php endif; ?>><?php echo $this->_tpl_vars['item']->name; ?>
</option>
									<?php endforeach; endif; unset($_from); ?>
								</select>
							</th>
							<th>
								<select name="deal_status">
									<option value="-1">Tất cả</option>
									<?php $_from = $this->_tpl_vars['dealStatusList']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars['key'] => $this->_tpl_vars['item']):
?>
										<option value="<?php echo $this->_tpl_vars['key']; ?>
" <?php if ($this->_tpl_vars['key'] == $this->_tpl_vars['deal_status']): ?>selected<?php endif; ?>><?php echo $this->_tpl_vars['item']; ?>
</option>
									<?php endforeach; endif; unset($_from); ?>
								</select>
							</th>
							<th ><input class="button" type="submit" value="Tìm" name="submit"></th>
	
						</tr>
					</thead>
					<tbody>
						<?php $_from = $this->_tpl_vars['itemList']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }$this->_foreach['pageList'] = array('total' => count($_from), 'iteration' => 0);
if ($this->_foreach['pageList']['total'] > 0):
    foreach ($_from as $this->_tpl_vars['item']):
        $this->_foreach['pageList']['iteration']++;
?>
						<tr>
							<td><?php echo $this->_tpl_vars['item']['deal_id']; ?>
</td>
							<td><?php echo $this->_tpl_vars['item']['groupon_name']; ?>
</td>
							<td><?php echo $this->_tpl_vars['item']['started_deal']; ?>
</td>
							<td><?php echo $this->_tpl_vars['item']['expired_deal']; ?>
</td>
							<td><?php echo ((is_array($_tmp=$this->_tpl_vars['item']['sale_price'])) ? $this->_run_mod_handler('number_format', true, $_tmp) : number_format($_tmp)); ?>
</td>
							<td><?php echo ((is_array($_tmp=$this->_tpl_vars['item']['original_price'])) ? $this->_run_mod_handler('number_format', true, $_tmp) : number_format($_tmp)); ?>
</td>
							<td><?php echo $this->_tpl_vars['item']['category_name']; ?>
</td>
							<td><?php echo $this->_tpl_vars['dealEntity']->getStatusName($this->_tpl_vars['item']['deal_status']); ?>
</td>
							<td valign="middle">
								<div style="float: right;">
								<?php if ($this->_tpl_vars['item']['deal_status'] == 0): ?>
									<a class="kichhoat_url" id="kichhoat_url_<?php echo $this->_tpl_vars['item']['deal_id']; ?>
" href="#kichhoat_form"  rel="<?php echo $this->_tpl_vars['item']['deal_id']; ?>
">Kích hoạt</a>
									<a target="_blank" href="<?php echo $this->_tpl_vars['APPLICATION_URL']; ?>
/Admin/Deals/edit/id/<?php echo $this->_tpl_vars['item']['id']; ?>
">
										<img src="<?php echo $this->_tpl_vars['APPLICATION_URL']; ?>
/Themes/Default/Images/b_edit.png" alt="" />
									</a>
									<!-- <a href="javascript:void(0);" onclick="if (confirm('Are you sure you want to delete this record?')) { deleteAction(<?php echo $this->_tpl_vars['grouponEntity']->id; ?>
); } else { return false; }" class="notboldText">
										<img src="<?php echo $this->_tpl_vars['APPLICATION_URL']; ?>
/Themes/Default/Images/b_drop.png" alt="" />
									</a>-->
								<?php else: ?>
									<a href="<?php echo $this->_tpl_vars['APPLICATION_URL']; ?>
/Admin/DealOrder/showorder/deal_id/<?php echo $this->_tpl_vars['item']['deal_id']; ?>
">Xem đơn hàng</a>
								<?php endif; ?>
								</div>
							</td>
						</tr>
						<?php endforeach; endif; unset($_from); ?>
					</tbody>
				</table>
				</form>
			</div>
			
			<div class="paging" style="text-align:center;">
			<?php echo $this->_tpl_vars['pageLink']; ?>

			</div>
		</div>
	</div>
</div>

<form name="frmDelete" method="post">
<input type="hidden" name="idValue" value="" />
<input type="hidden" id="actionKey" name="actionKey" value="<?php echo $this->_tpl_vars['actionKey']; ?>
" />
</form>
<script type="text/javascript">
function deleteAction(value){
	var theform = document.frmDelete;
	theform.idValue.value = value;
	theform.action = "<?php echo $this->_tpl_vars['APPLICATION_URL']; ?>
/Admin/Deals/delete";
	theform.submit();
	return true;
}

$(function() {
	$("#started_deal").datepicker();
});
</script>
<script type="text/javascript">
function deleteAction(value){
	var theform = document.frmDelete;
	theform.idValue.value = value;
	theform.action = "<?php echo $this->_tpl_vars['APPLICATION_URL']; ?>
/Admin/Deals/delete";
	theform.submit();
	return true;
}
$(document).ready(function(){

	$(".kichhoat_url").click(function(){
		// do whatever here
	      var deal_id = $(this).attr('rel');     
	      $("#aFDeal_id").val(deal_id);
	});
	
    $(".kichhoat_url").fancybox({
		'scrolling'		: 'no',
		'titleShow'		: false,
		'onClosed'		: function() {
		},
		'onStart' : function(){
		      
		}
	});
});
function approveDeal() {		
 	var checkResult = true;
 	var form = document.approveForm;
 	$.fancybox.showActivity();
 	if(form)
 	{
	 	$.ajax({
			type		: "POST",
			cache	: false,
			dataType: 'json',
			url		: "<?php echo $this->_tpl_vars['APPLICATION_URL']; ?>
/Admin/Deals/approve",
			data		: $(".approveForm").serializeArray(),
			success: function(obj) {
				if (typeof obj["success"] != "undefined" && (obj["success"] == "1" || obj["success"] == 1)) {				
					$.fancybox.close();
					window.location.reload();					
				}
			}
		});
	 	
		return false;
 	}
	
 	return false;
	}
</script>
<div style='display: none'>
	<div id="kichhoat_form">
		<div id="main-content">
			<div class="two-column alpha">
				<h4 class="article-title">Xác nhận</h4>
				<form action="<?php echo $this->_tpl_vars['APPLICATION_URL']; ?>
/Admin/Deals/approve" method="post"
					id="approveForm" name="approveForm" class="approveForm" onsubmit="return approveDeal();">
					<p>Bạn có chắc sẽ kích hoạt deal này. Ngay khi bạn kích hoạt, deal này sẽ được bán ngay lập tức.</p>
					
					<button>Đồng ý</button> hay <a href="#" onclick="$.fancybox.close();">Thoát</a>
					<input type="hidden" value="" id="aFDeal_id" name="deal_id"> 
				</form>
				<div class="clear"></div>
			</div>			
		</div>
	</div>
</div>